import request from '@/common/utils/request'
import {
	serv
} from '@/common/utils/config'

//获取购物车商品列表
export function cart(data) {
	return request(serv.order + '/api/cart/MyCart', {
		method: 'post',
		data: data
	})
}

// export function cart() {
// 	return request(serv.order + '/api/cart', {
// 		method: 'get'
// 	})
// }

//删除购物车商品
export function remove(data) {
	return new Promise((resolve, reject) => {
		request(serv.order + '/api/cart/delete_item', {
			method: 'post',
			data: data,
			header: {
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}).then(res => {
			resolve(res);
		})
	})
}

//编辑数量
export function edit(data) {
	return new Promise((resolve, reject) => {
		request(serv.order + '/api/cart/edit', {
			method: 'post',
			data: data,
			header: {
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}).then(res => {
			resolve(res);
		})
	})
}

//复选框改变
export function checkChange(data) {
	return new Promise((resolve, reject) => {
		request(serv.order + '/api/cart/checkbox_change', {
			method: 'post',
			data: data,
			header: {
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}).then(res => {
			resolve(res);
		})
	})
}

// 加入购物车
export function addToCart(data) {
	return request(serv.order + '/api/cart/addCart', {
		method: 'post',
		data: data
	})
}

export function checkSkip(data) {
	return request(serv.order + '/api/cart/check_skip', {
		method: 'get',
		data: data
	})
}
//切换地区查看商品可采性、库存和价格
export function checkGoodsCable(data) {
	return request(serv.order + '/api/goods/getGoodsBuyCheck', {
		method: 'get',
		data: data
	})
}
//购物车添加收藏 productId
export function addGoodCart(data) {
	return request(serv.order + '/api/favorites_product/addCollection', {
		method: 'post',
		data: data
	})
}
